#include "clkObject.h"

clkObject::clkObject()
{
	m_body = 0;
	m_shape = 0;
}

clkObject::~clkObject()
{
	destroy();
}

void clkObject::destroy()
{
	SAFE_DELETE(m_body);
	SAFE_DELETE(m_shape);
}

void clkObject::update()
{

}

void clkObject::setPosition(V2DF a_position)
{
	m_body->m_position = a_position;

	clkRect* rect = RECT(m_shape);
	for(int i = 0; i < 4; i++)
		rect->m_rverts[i] = m_body->m_position + rect->m_averts[i];
}

void clkObject::setRotation(float a_rotation)
{
	float dif = a_rotation - m_body->m_rotation;
	if(dif == 0.0f) return;

	m_body->m_rotation = a_rotation;

	clkRect* rect = RECT(m_shape);
	for(int i = 0; i < 4; i++)
	{
		rotateVec(rect->m_averts[i],dif);
		rotateVec(rect->m_norms[i],dif);
	}
	rotateVec(m_shape->m_dir,dif);
}

float clkObject::getWidth()
{
	if(m_shape->m_type == SHAPE_CIRCLE) return 0;
	return RECT(m_shape)->m_width;
}

float clkObject::getHeight()
{
	if(m_shape->m_type == SHAPE_CIRCLE) return 0;
	return RECT(m_shape)->m_height;
}

int clkObject::getVertCount()
{
	if(m_shape->m_type == SHAPE_CIRCLE) return 0;
	return RECT(m_shape)->m_vertCount;
}

V2DF* clkObject::getAVerts()
{
	if(m_shape->m_type == SHAPE_CIRCLE) return 0;
	return RECT(m_shape)->m_averts;
}

V2DF* clkObject::getRVerts()
{
	if(m_shape->m_type == SHAPE_CIRCLE) return 0;
	return RECT(m_shape)->m_rverts;
}

V2DF* clkObject::getNorms()
{
	if(m_shape->m_type == SHAPE_CIRCLE) return 0;
	return RECT(m_shape)->m_norms;
}